package com.alibaba.middleware.hsf.guide.io.listener;

import com.taobao.hsf.annotation.Order;
import com.taobao.hsf.annotation.Scope;
import com.taobao.hsf.annotation.Tag;
import com.taobao.hsf.io.client.Client;
import com.taobao.hsf.io.stream.ClientStream;
import com.taobao.hsf.io.stream.support.ClientStreamLifecycleListenerAdapter;

import java.net.SocketAddress;

/**
 * @author weipeng2k 2018年03月02日 下午13:30:05
 */
@Tag({"tcp", "http"})
@Scope(Scope.Option.SINGLETON)
@Order(10000)
public class TestClientStreamLifecycleListener extends ClientStreamLifecycleListenerAdapter {

    @Override
    public void connectFailed(Client client, SocketAddress localAddress, SocketAddress remoteAddress, int timeout,
                              Throwable cause) {
        System.out.println("client@" + client + " can not establish conn to " + remoteAddress);
    }

    @Override
    public void idle(Client client, ClientStream stream) {
        System.out.println("client@" + client + " conn to " + stream + " idle");
    }

    @Override
    public void connectSuccess(Client client, ClientStream stream) {
        System.out.println("client@" + client + " establish conn to " + stream.getRemoteAddress());
    }

    @Override
    public void close(Client client, ClientStream stream) {
        System.out.println("client@" + client + " close conn to " + stream.getRemoteAddress());
    }

}
